;
(function() {
	var skill = {

		save: function() {
			db.update(config.dbname.dotnarMessage, this._id, this);
		},
		destroy: function() {
			db.remove(config.dbname.dotnarMessage, this._id);
		},
		//非安全
		_setInfo: function(info) {
			/*
			 * TODO:填平参数
			 */
			this._initInfo(info);
			this.save();
			return this._id;
		},
		_initInfo: function(info) {
			info.title = info.title ? info.title.trim() : "";
			info.name = info.name ? info.name.trim() : "";
			info.email = info.email ? info.email.trim() : "";
			info.content = info.content ? info.content.trim() : "";
			if (!info.title) {
				throwCusError("留言标题不可为空")
			}
			if (info.title.length > config.messageTitleLength) {
				throwCusError("留言标题过长")
			}
			this.info.title = info.title;
			if (!info.name) {
				throwCusError("留言称呼不可为空")
			}
			this.info.name = info.name;
			if (!info.email) {
				throwCusError("留言邮箱不可为空")
			}
			this.info.email = info.email;
			if (!info.content) {
				throwCusError("留言正文不可为空")
			}
			if (info.content.length > config.messageContentLength) {
				throwCusError("留言内容过多")
			}
			this.info.content = info.content;
		},
		_addReply: function(replyer_info, reply_content) {
			var self = this;
			var replyContent = {
				// from: {
				// 	name: replyer_info.name,
				// 	address: replyer_info.email || "dotnar@163.com"
				// },
				// pass: replyer_info.email_password || "dianna123456",
				to: this.info.email,
				title: "回复：" + this.info.title,
				content: reply_content
			};
			console.log(replyContent);
			emailSender(replyContent, function(error) {
				if (error) {
					console.error("邮件发送失败", replyContent, error);
				} else {
				}
			});
			self.reply.push(replyContent);
			self.save();
		}
	}
	module.exports = skill;

	var db = require("../db/index");
	var config = require("../_include/config");
	var UserAddressCon = require("../user_address/_con");
	var AchCon = require("../ach/_con");
	var data_cut = require("../_include/data_cut");
	var CommentCon = require("../comment/_con");
	var EvaluationCon = require("../eval/_con");
	var ClassifyCon = require("../bus.classify/_con");
	var TagCon = require("../bus.tag/_con");
	var BuffCon = require("../buff/_con");
	var buffCode = require("../buff/buff_code");
	var $Object = require("../_include/$.Object");
	var helper = require("../_include/helper");
	var emailSender = require("../_include/email");

}());